package com.yuanhua.xcxmng.wechat.controller;

import com.sun.xml.internal.rngom.parse.host.Base;
import com.yuanhua.xcxmng.wechat.cache.LocalCache;
import com.yuanhua.xcxmng.wechat.entity.UserLocation;
import com.yuanhua.xcxmng.wechat.service.LocationService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wechat/location")
public class LocationController extends BaseController {

    @Autowired
    private LocationService locationService;

    @GetMapping("save")
    public void save(UserLocation userLocation, String threeSession) throws Exception {
        // 用户信息校验
        if (StringUtils.isBlank(threeSession)) {
            return;
        }
        String sessionCode = LocalCache.getInStance().getLocalCache(threeSession);
        if (StringUtils.isBlank(sessionCode)) {
            return;
        }
        String openId = StringUtils.split(sessionCode, "^#^")[1];
        userLocation.setOpenId(openId);
        locationService.insert(userLocation);
    }

}
